package com.socialuni.sdk.service;

import com.socialuni.sdk.api.model.RO.user.base.SocialUserRO;
import com.socialuni.sdk.domain.SocialUserDODomainCreate;
import com.socialuni.sdk.model.DO.user.UserDO;
import com.socialuni.sdk.model.ProviderLoginQO;
import com.socialuni.sdk.model.RO.UniLoginRO;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import javax.transaction.Transactional;

@Service
public class SocialUserLoginService {
    @Resource
    CommonUserLoginService commonUserLoginService;
    @Resource
    SocialUserDODomainCreate socialUserDODomainCreate;

    //通过渠道信息返回用户
    @Transactional
    public UniLoginRO<SocialUserRO> providerLogin(ProviderLoginQO loginQO) {
        //创建或返回
        UserDO user = socialUserDODomainCreate.getOrCreate(loginQO);

        //
        UniLoginRO<SocialUserRO> userROUniLoginRO = commonUserLoginService.createTokenAndToUserRO(user);
        return userROUniLoginRO;
    }
}